using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.Serialization;
using VSTalk.Tools;

namespace VSTalk.Model
{
    [DataContract]
    public class Client : INotifyPropertyChanged
    {
        private Guid _id;

        private string _login;

        private string _password;

        private string _server;

        private ObservableCollection<Interlocutor> _contacts;

        private ObservableCollection<Room> _rooms;

        private string _resource;

        #region PROPERTIES

        [DataMember]
        public string Server
        {
            get { return _server; }
            set
            {
                _server = value;
                PropertyChanged.Notify(() => Server);
            }
        }

        [DataMember]
        public Guid Id
        {
            get { return _id; }
            set
            {
                _id = value;
                PropertyChanged.Notify(() => Id);
            }
        }

        [DataMember]
        public string Login
        {
            get { return _login; }
            set
            {
                _login = value;
                PropertyChanged.Notify(() => Login);
            }
        }

        [DataMember]
        public string Resource
        {
            get { return _resource; }
            set
            {
                _resource = value;
                PropertyChanged.Notify(() => Resource);
            }
        }

        [DataMember]
        public string Password
        {
            get { return _password; }
            set
            {
                _password = value;
                PropertyChanged.Notify(() => Password);
            }
        }

        [DataMember]
        public ObservableCollection<Interlocutor> Contacts
        {
            get { return _contacts; }
            set
            {
                _contacts = value;
                PropertyChanged.Notify(() => Contacts);
            }
        }

        [DataMember]
        public ObservableCollection<Room> Rooms
        {
            get { return _rooms; }
            set
            {
                _rooms = value;
                PropertyChanged.Notify(() => Rooms);
            }
        }

        #endregion PROPERTIES

        public Client()
        {
            Contacts = new ObservableCollection<Interlocutor>();
            Rooms = new ObservableCollection<Room>();
        }

        [OnDeserializing]
        internal void OnDeserializing(StreamingContext context)
        {
            if (Contacts == null)
            {
                Contacts = new ObservableCollection<Interlocutor>();
            }
            if (Rooms == null)
            {
                Rooms = new ObservableCollection<Room>();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}